<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>关于数组函数的续讲</title>
</head>

<body>
    <div style="text-align: center;color: aquamarine;">第五次课</div>
    <script>
        let arr = ['你', '是', '天', '才']
        arr.splice(2, 0, '不', '是')
        console.log(arr)
        let arr1 = arr.slice(2, 4)
        console.log(arr1)
        let arr2 = arr.slice(2)
        console.log(arr2)
        let arr3 = [1, 2, 3, 4, 5] //1+2=3 3+3=6 6+4=10 10+5=15
        let sum = arr3.reduce((previousValue, currentValue) => {
            return previousValue * currentValue
        }, 0)
        console.log("乘积的结果" + sum)

        let length = arr.reduce((a, b) => {
                return a + b.length
            }, 0)
            //此处的0会影响reduce函数的初次计算，也就是将a+b替换为0+a
        console.log(length)

        //数组的遍历
        for (let i = 0; i < arr.length; i++) {
            console.log(arr[i])
        }
        let i = 0
        console.log("=================================================")
        while (i < arr.length) {
            console.log(arr[i])
            i++
        }
        console.log("=================================================")
        for (item of arr) {
            console.log(item)
        }
        //item 仅仅是自命名，可更改
        console.log("=================================================")
        for (index in arr) {
            console.log(index + arr[index])
        }
        //in 遍历出了索引,常应用于遍历对象属性的场景，不常用于数组
    </script>

</body>

</html>